﻿<Window x:Class="CodeAngel.UI.AggregateDefWindow"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        xmlns:system="clr-namespace:System;assembly=mscorlib"
        xmlns:local="clr-namespace:CodeAngel.UI"
        Title="Aggregate Definition" Height="500" Width="400" WindowStartupLocation="CenterOwner">

    <Window.Resources>

        <system:Double x:Key="LABEL_WIDTH">80.0</system:Double>

        <HierarchicalDataTemplate DataType="{x:Type local:AggregateDefItem}" ItemsSource="{Binding Children}" >
            <StackPanel Orientation="Horizontal">
                <CheckBox IsChecked="{Binding IsChecked}" Visibility="{Binding IsCheckedVisibility}" />
                <TextBlock Text="{Binding Header}" />
                <CheckBox Content="Updateable?" IsChecked="{Binding IsUpdateable}" Visibility="{Binding IsUpdateableVisibility}" Margin="6,0,0,0" FontSize="8" />
                <CheckBox Content="All Scalar Properties" IsChecked="{Binding IncludeAllScalarProperties}" Visibility="{Binding IncludeAllScalarPropertiesVisibility}" Margin="6,0,0,0" FontSize="8"/>
            </StackPanel>
        </HierarchicalDataTemplate>

        <Style TargetType="TreeViewItem" BasedOn="{StaticResource {x:Type TreeViewItem}}">
            <Setter Property="IsExpanded" Value="{Binding IsExpanded}" />
        </Style>

    </Window.Resources>
    
    <Grid Margin="10">
        <Grid.RowDefinitions>
            <RowDefinition Height="Auto" />
            <RowDefinition Height="*" />
            <RowDefinition Height="Auto" />
        </Grid.RowDefinitions>
        
        <StackPanel>
            <Grid>
                <Grid.ColumnDefinitions>
                    <ColumnDefinition Width="*"/>
                    <ColumnDefinition Width="Auto" />
                </Grid.ColumnDefinitions>
                <local:LabeledTextBox Label="Name" Text="{Binding AggregateDef.Name}"  LabelWidth="{StaticResource LABEL_WIDTH}" />
                <local:LabeledCheckBox Label="Create Stored Procedure" IsChecked="{Binding AggregateDef.CreateStoredProcedure}" Grid.Column="1" Margin="6,0,0,0" />
            </Grid>
            <local:LabeledCheckBox Label="Is Collection" IsChecked="{Binding AggregateDef.RootIsCollection}" LabelWidth="{StaticResource LABEL_WIDTH}"/>
            <local:LabeledTextBox Label="Description" Text="{Binding AggregateDef.Description}"  LabelWidth="{StaticResource LABEL_WIDTH}" Height="80" />            
        </StackPanel>

        <local:HorizontalLabeledControl Label="Data Elements" Grid.Row="1">
            <TreeView>
                <TreeViewItem ItemsSource="{Binding AggregateDefItem.Children}" IsExpanded="True">
                    <TreeViewItem.Header>
                        <StackPanel Orientation="Horizontal">
                            <TextBlock Text="{Binding AggregateDefItem.Header}" />
                            <CheckBox Content="Updateable?" IsChecked="{Binding AggregateDefItem.IsUpdateable}" Visibility="{Binding AggregateDefItem.IsUpdateableVisibility}" Margin="6,0,0,0" FontSize="8" />
                            <CheckBox Content="All Scalar Properties" IsChecked="{Binding AggregateDefItem.IncludeAllScalarProperties}" Visibility="{Binding AggregateDefItem.IncludeAllScalarPropertiesVisibility}" Margin="6,0,0,0" FontSize="8" />
                        </StackPanel>
                    </TreeViewItem.Header>

                </TreeViewItem>
            </TreeView>
        </local:HorizontalLabeledControl>


        <!-- Save and Cancel Buttons -->
        <StackPanel Orientation="Horizontal" Grid.Row="2"  HorizontalAlignment="Right" Margin="0,6,0,0">
            <Button Content="OK" Click="OkHandler" />
            <Button Content="Cancel" IsCancel="True" Margin="6,0,0,0" />
        </StackPanel>
    </Grid>
</Window>
